/*
*Copyright 2021-2023 NERCIS
*
*Licensed under the Apache License, Version 2.0 (the "License");
*you may not use this file except in compliance with the License.
*You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*Unless required by applicable law or agreed to in writing, software
*distributed under the License is distributed on an "AS IS" BASIS,
*WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*See the License for the specific language governing permissions and
*limitations under the License.
*/

package cn.ac.nercis.pes.common.constant.knowledge;


import org.apache.commons.lang3.StringUtils;

import java.util.Arrays;
import java.util.List;

/**
 * 虚拟资产分类
 * @author zpy
 * @version 1.0.0
 */
public enum VirtualClassification {
    /**物理和环境安全**/
    PHY_SECURITY("vc1","物理和环境安全", AssetClassification.PHY_ENV.getId(),AssetClassification.PHY_SECURITY.getId()),
    /**网络和通信安全**/
    NETWORK_SECURITY("vc2","网络和通信安全",AssetClassification.COMMUNICATION_CHANNEL.getId()),
    /**设备和计算安全**/
    DEVICE_SECURITY("vc3","设备和计算安全",AssetClassification.NETWORK_SECURITY.getId(),AssetClassification.PWD_PRODUCT.getId(),
            AssetClassification.SERVER_STORAGE.getId(),AssetClassification.DATABASE.getId()),
    /**应用和数据安全**/
    APP_SECURITY("vc4","应用和数据安全",AssetClassification.SUB_BUSINESS.getId(),AssetClassification.KEY_DATA.getId()),
    /**安全管理**/
    SECURITY_MANAGE("vc5","安全管理",AssetClassification.MANAGE_DOC.getId());

    private final String id;
    private final String name;
    private final List<String> classIds;

    VirtualClassification(String id,String name,String... ids) {
        this.id = id;
        this.name = name;
        this.classIds = Arrays.asList(ids);
    }

    public static VirtualClassification fromClassId(String classId){
        VirtualClassification data = null;
        for(VirtualClassification tt : VirtualClassification.values()){
            if(tt.classIds.stream().anyMatch(id-> StringUtils.equals(id,classId))){
                data = tt;
                break;
            }
        }
        return data;
    }

    public String getId() {
        return this.id;
    }

    public String getName(){
        return this.name;
    }

    public List<String> getClassIds(){
        return this.classIds;
    }

}